class Gadget < ActiveRecord::Base
  
  belongs_to :category
  has_many :installed_gadgets, :dependent=>:destroy
  has_many :users, :through=>:installed_gadgets
  
  has_attached_file :gadget_spec
  has_attached_file :photo,     
                    :styles => {:thumb=> "40x40",       
                                :main => "150x150>" }
           
  def self.load
    gadget = Gadget.create(:spec_url=>'http://brightkitegadget.googlecode.com/svn/trunk/BrightkiteGadget.xml',
                  :container_id=>'gadget-chrome1',
                  :title=>'Brightkite Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>2);
                  
    File.open('public/images/brightkite_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                 
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:8080/gadgets/files/twitter/TwitterGadget.xml',
                  :container_id=>'gadget-chrome2',
                  :title=>'Twitter Gadget',
                  :description=>'',
                  :category_id=>2);
                  
    File.open('public/images/twitter_logo.png', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:8080/gadgets/files/samplecontainer/examples/SocialHelloWorld.xml',
                  :container_id=>'gadget-chrome3',
                  :title=>'Social Hello World',
                  :description=>'',
                  :published => true,
                  :category_id=>3);
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/PeopleFinderGadget.xml',
                  :container_id=>'gadget-chrome4',
                  :title=>'PeopleFinder Gadget',
                  :description=>'A gadget that lets GM employees use the People Finder application for looking up GM employees.',
                  :published => true,
                  :category_id=>1);
                  
    File.open('public/images/gm_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/NotesGadget.xml',
                  :container_id=>'gadget-chrome5',
                  :title=>'Lotus Notes Gadget',
                  :description=>'A Gadget that lets GM employees view their Lotus Notes inbox.  Employees are able to open an email from within the Gadget also.',
                  :published => true,
                  :category_id=>1);
                  
    File.open('public/images/lotusnotes_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
    
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/AddressChangeGadget.xml',
                  :container_id=>'gadget-chrome14',
                  :title=>'Address Change Gadget',
                  :description=>'A Gadget that lets GM employees lookup and change their address.',
                  :published => true,
                  :category_id=>1);
                  
    File.open('public/images/gm_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
    
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/PowerTrainGadget.xml',
                  :container_id=>'gadget-chrome15',
                  :title=>'Power Train Gadget',
                  :description=>'A Gadget that lets GM employees view the Power Train application.',
                  :published => true,
                  :category_id=>1);
                  
    File.open('public/images/gm_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://dirk.balfanz.googlepages.com/contacts.xml',
                  :container_id=>'gadget-chrome6',
                  :title=>'Contacts',
                  :description=>'',
                  :published => true,
                  :category_id=>3); 
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/twitter/TwitterGadget.xml',
                  :container_id=>'gadget-chrome7',
                  :title=>'Yammer Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>2);
                  
    File.open('public/images/yammer_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/LinkedInGadget.xml',
                  :container_id=>'gadget-chrome8',
                  :title=>'LinkedIn Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>2);
                  
    File.open('public/images/linkedin_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:8080/gadgets/files/twitter/TwitterGadget.xml',
                  :container_id=>'gadget-chrome9',
                  :title=>'Delicious Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>2);
                  
    File.open('public/images/delicious_logo.png', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/NYTGadget.xml',
                  :container_id=>'gadget-chrome11',
                  :title=>'New York Times Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>5);
                  
    File.open('public/images/new_york_times_logo.gif', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
    
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/datetime.xml',
                  :container_id=>'gadget-chrome12',
                  :title=>'Date/Time Gadget',
                  :description=>'',
                  :published => true,
                  :category_id=>3);
                  
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/WeatherChannel.xml',
                  :container_id=>'gadget-chrome13',
                  :title=>'Weather Channel Gadget',
                  :description=>'A gadget that provides you with weather from the Weather Channel',
                  :published => true,
                  :category_id=>5);
                  
    File.open('public/images/weather_channel_logo.jpg', 'rb') { |photo_file| gadget.photo = photo_file } 
    gadget.save
    
    gadget = Gadget.create(:spec_url=>'http://localhost:3000/gadget_specs/flickr_photos.xml',
                  :container_id=>'gadget-chrome20',
                  :title=>'flickr Photos Gadget',
                  :description=>'A gadget that lets you view flickr photos',
                  :published => true,
                  :category_id=>5);
                  
    InstalledGadget.create(:user_id=>1,
                           :gadget_id=>4)
  end
  
end
